
$(document).ready(function() {
	initTable();
});


var initTable =function(){
	var table = new Table();
	//表格加载的字段
    var cloumns = [
		    {'data': 'nick_name'},
		    {'data': 'head_portrait','render': function (data) {return '<img style="max-width: 40px; max-height: 40px;"  src= "'+basePath+'/'+data+'" />';}},
		    {'data': 'phone_num'},
		    {'data': 'balance'},
		    {'data': 'frozen_balance'},
		    {'data': 'receive_address'},
		    {'data': 'receive_address_detail'},
		    {'data': 'agent_profit'},
		    {'data': 'agent_num'},
		    {'data': 'is_agent','render': function (data){if(data==0){return '<span class="label radius">未代理</span>';}else if(data==1){return '<span class="label label-warning radius">申请中</span>';}else if(data==2){return '<span class="label label-success radius">已代理</span>';}  return "输入有误"; }},
		    {'data': 'id','render':function(data,type,full){if(full.is_agent==1){return '<a title="通过申请" href="javascript:;" onclick="reset(\''+data+'\')" class="btn btn-primary radius size-MINI" style="margin-right:10px;" >通过申请</a>';} return '<a title="通过申请" class="btn disabled radius size-MINI" style="margin-right:10px;" >通过申请</a>'; }}
		  ];
	//设置URL和加载的字段
    table.setting(basePath+"/user/getUserList","",cloumns);
	//调用表格分页
    table.tablePage();
}


var reset = function(id){
	layer.confirm('确认要通过该帐号的申请吗?',function(index){
		//此处请求后台程序，下方是成功后的前台处理……
		$.ajax({
			type:"post",
			url:basePath+"/user/passUser",
			data:{"id":id},
			success:function(data){
				if(data.code == "-3"){
					forwardLogin();
		    		return false;
	        	}
				if(data.code=="0"){
					layer.msg('审批通过',{icon:1,time:1000});
					initTable();
				}else{
					alert('error');
				}
			}
		});
		
		
	});
}

